﻿using System;
using UnityEngine;

namespace FrameWork
{
    static  public class MethodExtension
    {

        static public T GetOrAddComponent<T>(this GameObject go) where T:Component
        {
            T ret = go.GetComponent<T>();
            if (null == ret)
            {
                ret = go.AddComponent<T>();
            }
            return ret;
        }

        static public T GetOrAddComponent<T>(this Transform tf) where T : Component
        {
            T ret = tf.GetComponent<T>();
            if (null == ret)
            {
                ret = tf.gameObject.AddComponent<T>();
            }
            return ret;
        }

    }
}
